﻿using Fonour.Application.UserApp;
using Fonour.Domain.IRespositories;
using Fonour.EntityFrameworkCore;
using Fonour.EntityFrameworkCore.Repositories;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Fonour.MVC
{
    public class Startup
    {
        private readonly IConfiguration Configuration;

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped<IUserRepository, UserRepository>();
            services.AddScoped<IUserAppService, UserAppService>();

            services.AddDbContext<FonourDbContext>(options =>
            {
                options.UseMySQL(Configuration.GetConnectionString("Fonour"));
            }, ServiceLifetime.Scoped);
            
            services.AddMvc();
            services.AddSession();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Shared/Error");
            }

            app.UseStaticFiles();

            app.UseSession();

            app.UseMvc((route) =>
            {
                route.MapRoute(
                    name: "default",
                    template: "{controller=Login}/{action=Index}/{id?}"
                );
            });
            // SeedData.Initialize(app);
        }
    }
}
